<?php

use mytharcher\sdk\alipay\Alipay;

class BizcardAction extends Action{
    
	private $Bizcard ;
	
	function _initialize(){
		$this->theme("Bizcard");
		
		$hash = $_GET['hash'];
		
		if(empty($hash)){
			$hash = 'a067eb9c816d';
		}
		$ob = M("csl_customer");
		
		if(strlen($hash)<5){
			$this->Bizcard = $ob->where(array('sourceid'=>$hash))->find();
		}else{
			$this->Bizcard = $ob->where(array('hash'=>$hash))->find();
		}
		
	}
	
	function home(){
		
		$this->detail();
	}
	
	function detail(){
		$hash = $_GET['hash'];
		
		if(empty($hash)){
			$hash = 'a067eb9c816d';
		}
		$ob = M("csl_customer");
		
		if(strlen($hash)<5){
			$info = $ob->where(array('sourceid'=>$hash))->find();
		}else{
			$info = $ob->where(array('hash'=>$hash))->find();
		}
		
		
		if(!empty(session('info'))){
		    $loginInfo = $ob->where(array('hash'=>session('info.hash')))->find();
		    $this->assign('loginInfo',$loginInfo);
		}
		
		vendor('phpqrcode.phpqrcode');
		
		
		$str =
		"BEGIN:VCARD
VERSION:4.0	O
FN:{$info[name]}
ORG:{$info[company]}
TITLE:{$info[title]}
TEL;TYPE=work,voice;VALUE=uri:{$info[mobile]}
TEL;TYPE=home,voice;VALUE=uri:{$info[telephone]}
ADR;TYPE=WORK:;;{$info[address]}
URL:http://25mp.cn/card/{$info[hash]}
NOTE:http://25mp.cn/card/{$info[hash]}
EMAIL:{$info[email]}
REV:".date('Y-m-d H:i:s')."
END:VCARD";
		
		QRcode::png($str,DATA_PATH.$info[hash].'_bizcard.png',QR_ECLEVEL_L,15);
		

		Vendor("WxJS.AutoLoad");
		$jssdk = new JSSDK(C("WX_APP_ID"), C("WX_APP_SECRET"));
		$signPackage = $jssdk->GetSignPackage();
		$this->assign('signPackage',$signPackage);
		
		$info['lastmodify'] = filemtime(DATA_PATH.$info['hash'].'_bizcard.png');

		$this->assign('info',$info);
		$this->display('Bizcard/detail');
		
	}
	
	function info(){
	    $hash = $_GET['hash'];
	
	    if(empty($hash)){
	        $hash = 'a067eb9c816d';
	    }
	    $ob = M("csl_customer");
	    $info = $ob->where(array('hash'=>$hash))->find();
	
	    $this->assign('info',$info);
	    $this->display('Bizcard/detail');
	
	}
	
	function pos(){
	    
	    $this->display('Bizcard/pos');
	}
	
	function intro(){
	     
	    $hash = $_GET['hash'];
	    $ob = M("csl_customer");
	    $info = $ob->where(array('hash'=>$hash))->find();
        //正则表达式强制替换iframe的width、height	     
	    $info['video_url'] = preg_replace("/iframe.+src/","iframe width='370' height='250' src",$info['video_url']);
	  
	    $this->assign('info',$info);
	    Log::write("转换后的video_url====".$info['video_url']);
	    if(!empty($info['introduction_simple'])){
	        
	        $oc = M("csl_files");
	        $list = $oc->where(array('cid'=>$info['cid']))
	                   ->order(array('orderby'=>'asc'))->select();
	        
	        $this->assign('list',$list);
	    }
	    
	    $this->display('Bizcard/intro');
	}
	
	function navigation(){
		
		Vendor("WxJS.AutoLoad");
		
		$jssdk = new JSSDK(C("WX_APP_ID"), C("WX_APP_SECRET"));
		$signPackage = $jssdk->GetSignPackage();
		$this->assign('signPackage',$signPackage);
		
		$hash = $_GET['hash'];
		$ob = M("csl_customer");
		$info = $ob->where(array('hash'=>$hash))->find();
		$this->assign('info',$info);
		
		
		$this->display('Bizcard/navigation');
	}
	
	function BizInfo(){
		$hash = $_GET['hash'];
		if(empty($hash)){
			$hash = 'a067eb9c816d';
		}
		$ob = M("csl_customer");
		$info = $ob->where(array('hash'=>$hash))->find();
		$this->assign('info',$info);
		
		import('@.Common.BizQuery');
		$biz = BizQuery::getyjapi($info['company']);
		$this->assign('biz',$biz['Result']);
		
		$this->display('Bizcard/BizInfo');

	}
	
	
	function login(){
	    $hash = $_GET['hash'];
	    if(empty($hash)){
	        $hash = 'a067eb9c816d';
	    }
	    
	    $ob = M("csl_customer");
	    if($_POST){
	        $login = $ob->where(array('mobile'=>$_POST['mobile'],'password'=>md5($_POST['password'])))->find();
	        if($login){
	            session('info',$login);
	            $this->redirect('/bizcard/account/hash/'.$login['hash']);
	            return ;
	        }else{
	        	$this->error("账号或密码错误!");
	        	return;
	        }
	    }
	    $info = $ob->where(array('hash'=>$hash))->find();
	    
	    $this->assign('info',$info);
	    $this->display('Bizcard/login');
	}
	
	function logout(){
	    session('info',null);
	    session_destroy();
	    $this->redirect('/bizcard/detail/hash/'.$_GET['hash']);
	}
	
	function forget(){
		if ($_POST){
			Log::write("POST['msgCode'] ===" .$_POST['msgCode']);
			Log::write("session(msgCode) ===" .session("msgCode"));
			if ($_POST['msgCode'] == session("msgCode")){
				
				
				if ($_POST['password'] == $_POST['passwordConfirm']){
					$ob = M("csl_customer");
					
					$info = $ob->where(array("mobile"=>$_POST["mobile"]))->find();
					if ($info){
						$_POST["password"] = md5($_POST['password']);
						$ob->where(array("mobile"=>$_POST["mobile"]))->save($_POST);
						
						$this->redirect("/Bizcard/detail/hash/".$_GET['hash']);
					}else{
						$this->error("该手机号码不存在!");
					}
					
				}else{
					$this->error("两次密码不一致!");
				}
				
			}else{
				$this->error("验证码错误!");
			}
			
			return;
		}
	    $this->display('Bizcard/forget');
	}
	
	/**
	 * 短信验证码
	 */
	function sendMsg(){
		for ($i=0; $i<4; $i++){
			$output .= rand(0, 9);
		}
		$content = CommonFunc::SendVerifySMS($_GET["mobile"], $output);		
// 		Log::write("验证码结果===" . print_r($content,true));
		echo json_encode($content);
	}
	
	function checkMobileIsExists(){
		if ($_GET['mobile']){
			$ob = M('csl_customer');
			$info = $ob->where(array("mobile"=>$_GET['mobile']))->find();
			if ($info){
				$result["status"] = "1"; 
			}else{
				$result["status"] = "0";
			}
			echo json_encode($result);
		}
	}

	function account(){
        $this->check();

        
		Vendor("WxJS.AutoLoad");
		$jssdk = new JSSDK(C("WX_APP_ID"), C("WX_APP_SECRET"));
		$signPackage = $jssdk->GetSignPackage();
		$this->assign('signPackage',$signPackage);
	    
	    $ob = M("csl_customer");
	    $info = $ob->where(array('hash'=>session("info.hash")))->find();
	    
	    $this->assign('info',$info);
	    $this->display('Bizcard/account');
	}
	
	function AccountInfo(){
		$this->check();
		 
		$ob = M("csl_customer");
		$info = $ob->where(array('hash'=>session("info.hash")))->find();
		
		$this->assign('info',$info);
		$this->display('Bizcard/accountinfo');
	}
	
	function ModifyAccount(){
		Log::write("FILES1_size===".print_r($_FILES['Avatar']['size'], true));
// 		Log::write("FILES1_name===".print_r($_FILES['Avatar']['name'], true));

	    $this->check();
	    $ob = M("csl_customer");
	    if($_POST){
	    	if(!empty($_FILES['Avatar']['name']) && $_FILES['Avatar']['size'] > 3700000){  // >9M的文件的处理
	    		$this->error("文件过大上传失败。");
	    		return;
	    	}else if(!empty($_FILES['Avatar']['name']) && $_FILES['Avatar']['size'] == 0){ //<9M,>3M的文件的处理
	    		$this->error("上传文件过大!");
	    		return;
	    	}else if($_FILES['Avatar']['size'] > 0){
	    		$flag = $this->uploadAvatar();
	    		if ($flag !== true){
	    			$this->error($flag);
	    			return;
	    		} 
	    	}
	        $ob->where(array('hash'=>session("info.hash")))->save($_POST);
	        $this->redirect('/bizcard/ModifyAccount/');
	    }
	    $info = $ob->where(array('hash'=>session("info.hash")))->find();
	    
	    $this->assign('info',$info);
	    $this->display('Bizcard/modify_account');
	}
	
	function modifyCompanyInfo(){
	    $this->check();
	    
	    $oc = M("csl_customer");
	    $ob = M("csl_files"); 
	    
	    if($_GET['delete']!=""){
	        $info = $ob->where(array('fid'=>$_GET['delete'],'cid'=>session("info.cid")))->find();
	        @unlink( APP_PATH. $info['path']);
	        $ob->where(array('fid'=>$_GET['delete'],'cid'=>session("info.cid")))->delete();
	        $this->redirect('/bizcard/modifyCompanyInfo');
	        return ;
	    }
	    
	    if($_POST['fid']!=""){
	        $ob->where(array('fid'=>$_POST['fid']))
	           ->setField(array('orderby'=>intval($_POST['orderby'])));
	        $this->redirect('/bizcard/modifyCompanyInfo');
	        return ;
	    }
	    
	    if($_POST){
	       if (!empty($_POST['video_url'])){
	           $_POST['video_url'] = str_replace('"', "'",  $_POST['video_url']);
	       }
	       $oc->where(array('cid'=>session("info.cid")))
	          ->setField(array('introduction_simple'=>$_POST['introduction_simple'],'video_url'=>$_POST['video_url']));
	      
	       if($_FILES){
	           mkdir(APP_PATH.'/files/company/');
	           import('ORG.Net.UploadFile');
	           if(strpos($_FILES['company']['name'][0], '.')===false){
	           	//修复部分安卓手机bug
	           		$_FILES['company']['name'][0] = 
	           		$_FILES['company']['name'][0].".jpg";
	           }
				
	           $upload = new UploadFile();// 实例化上传类
	           $upload->maxSize  = 6145728 ;// 设置附件上传大小
	           $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
	           $upload->savePath =  './files/company/'.date('Ym').'/';// 设置附件上传目录
	           $upload->thumb = true;
	           $upload->thumbType = 0;
	           $upload->thumbPrefix = "cmp_";
	           $upload->thumbMaxWidth = '500';
	           $upload->thumbMaxHeight = '1000';
	           $upload->thumbRemoveOrigin = true;
	           if(!$upload->upload()) {// 上传错误提示错误信息
	               // 	            $this->error($upload->getErrorMsg());
// 	               $this->error($upload->getErrorMsg().print_r($_FILES));
	           		           print_r($_FILES);
	           		           exit();
	           }else{// 上传成功 获取上传文件信息
	               $info =  $upload->getUploadFileInfo();
	           }
	            
	           if(!empty($info)){
	               foreach($info as $key=>$value){
	                   $data['path'] = '/files/company/'.date('Ym').'/cmp_'.$value['savename'];
	                   $data['cid'] = session("info.cid");
	                   $ob->add($data); // 写入用户数据到数据库
	               }
	               $this->success('数据保存成功！');
	           }
	       }
	       $this->redirect('/bizcard/modifyCompanyInfo');
	       return ;
	    }
	    
	    
	    $info = $oc->where(array('cid'=>session("info.cid")))->find();
	    $list = $ob->where(array('cid'=>session("info.cid")))
	                   ->order(array('orderby'=>'asc'))->select();
	    
	    $info['video_url'] = str_replace('"', "'",  $info['video_url']);
	    
	    $this->assign('info',$info);
	    $this->assign('list',$list);
	    $this->display('Bizcard/modify_company');
	}
	
	function doAfter(){
		$this->redirect('/bizcard/detail/hash/36');
//         $this->display('Bizcard/updatePro');
    }
	
    function check(){
	    if(!session('info')){
	        $this->redirect('/Bizcard/login/hash/'.$_GET['hash']);
	        exit();
	    }
    }

    function holiday(){
    	$this->theme('Bizcard');
    	$this->display('Bizcard:holiday');
    }
    
    function createOrder(){
    	$this->theme('Bizcard');
    	//暂时修改
//     	$this->redirect("/Bizcard/holiday");
//     	return;
    	
    	if($_POST){
	        $no = createOrderNo();
            $randNum = rand(1000,9999);
            $_POST['order_no'] = $no.$randNum;  //订单号
	        
	        $_POST['uid'] = 0;// session('info.uid');		//下单人
	        $_POST['cid'] = $this->Bizcard['cid'];// session('info.uid');		//前台下单人
	        $_POST['order_item_price'] = 44;
	        $_POST['order_price'] = $_POST['number']*$_POST['order_item_price'];			//订单总金额
	        
	        if(empty($_POST['order_status'])){
	            $_POST['order_status'] = '1';//订单状态
	        }
// 	        $order = new OrderAction();
// 	        $upload = $order->uploadCard();
// 	        if($upload){
// 	            $_POST['order_img'] = $upload;
// 	        }
	        	
	        $_POST['ctime'] = date('Y-m-d H:i:s',time());		//生成时间
	        $_POST['order_coupon_price'] = 0;
	        $_POST['order_shipping_cost'] = 0;
	        $data = $_POST;
	        $ob = M("csl_order");
	     /*   if($_POST['oid'] != ''){
	            $ob->where(array('oid'=>$_POST['oid']))->save($data);
	        }else{
	            $ob->add($data);
	        }*/

	        $ob->add($data);
	        $this->redirect('/Bizcard/detail/hash/'.$_GET['hash']);
	        return ;
	    }
		
	    if ($_GET['opt'] == 'add'){
	    	$hash = $_GET['hash'];
			if(empty($hash)){
				$hash = 'a067eb9c816d';
			}
			$ob = M("csl_customer");
			$info = $ob->where(array('hash'=>$hash))->find();
			$this->assign('info',$info);
			
	    	$this->display("/Bizcard/createOrder");
			return;
	    }
    }
    
    
    function uploadAvatar(){
    	import('ORG.Net.UploadFile');
    	$upload = new UploadFile();// 实例化上传类
    	$upload->maxSize  = 3145728 ;// 设置附件上传大小
    	$upload->thumb  = true ;// /设置需要生成缩略图，仅对图像文件有效
    	$upload->thumbMaxWidth  = 150 ;// 设置附件上传大小
    	$upload->thumbMaxHeight  = 150 ;// 设置附件上传大小
    	$upload->thumbPrefix  = '' ;// 设置附件上传大小
    	$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    	$upload->savePath =  TEMP_PATH;// 设置附件上传目录
    	if(!$upload->upload()) {// 上传错误提示错误信息
//     		Log::write("上传图片错误====". $upload->getErrorMsg());
//     		$this->error($upload->getErrorMsg());  //提示错误信息
    		return $upload->getErrorMsg();
    	}else{// 上传成功 获取上传文件信息
    		$info1 =  $upload->getUploadFileInfo();
    
    		$image_file = $info1[0]['savepath'].$info1[0]['savename'];
    		$image_info = getimagesize($image_file);
    		$base64_image_content = "data:{$image_info['mime']};base64," . (base64_encode(file_get_contents($image_file)));
    		@unlink($image_file);
    			
    		if (isset($_FILES['Avatar']))
    			$_POST['Avatar'] =  $base64_image_content;
    
    		if (isset($_FILES['pay_two_code']))
    			$_POST['pay_two_code'] =  $base64_image_content;
    			
    		return true;
    	}
    }
    
    /**
     * 我的订单 --订单列表
     */
    function orderList(){
    	$this->theme("Bizcard");
    	$hash = $_GET['hash'];
    
    	$ob = M("csl_customer");
    	$info = $ob->where(array('hash'=>$hash))->find();  //通过hash找到下单人
    
    	$db = M("csl_order");
    	$orderlist = $db->where(array("cid"=>$info['cid']))->order("ctime desc")->select();  //$info['cid']
    
    	$this->assign("orderlist", $orderlist);
    	$this->display("/Bizcard/orderList");
    	return;
    }
    
    /**
     * 前端提现页面
     */
    function cashlist(){
    	$ob = M("csl_cash");
    
    	$cid = $_GET['cid']==''?session('info.cid'):$_GET['cid'];
    
    	$db = M("csl_customer");
    	$info = $db->where(array('cid'=>$cid))->find();
    
    	$list = $ob->where(array('cid'=>$cid))->select();
    
    	$this->assign("list", $list); //提现记录
    
    	$this->assign("info", $info);  //账号记录
    	$this->display("/Bizcard/cashlist");
    	return;
    }
    
     /*上传个人微信二维码*/
    function uploadWxTwo(){
        $ob = M('csl_customer');
        if($_FILES){
            Log::write("上传图片name====". $_FILES["wxImg"]["name"]);
            Log::write("上传图片type====". $_FILES["wxImg"]["type"]);
            
            if (!is_dir(APP_PATH.'/files/wxTwoCode/'.date('Ym').'/')){
                mkdir(APP_PATH.'/files/wxTwoCode/'.date('Ym').'/',0755,true);
            }
            
            import('ORG.Net.UploadFile');
            $upload = new UploadFile();// 实例化上传类
            $upload->maxSize  = 3145728 ;// 设置附件上传大小
            $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->savePath =  './files/wxTwoCode/'.date('Ym').'/';// 设置附件上传目录
            if(!$upload->upload()) {// 上传错误提示错误信息
                $this->error($upload->getErrorMsg());
                return;
            }else{// 上传成功 获取上传文件信息
                $info =  $upload->getUploadFileInfo();
            }
        
            if(!empty($info)){
                foreach($info as $key=>$value){
                    $data['wx_img_url'] = '/files/wxTwoCode/'.date('Ym').'/'.$value['savename'];
                    Log::write("path==".print_r($data['wx_img_url'],true));
                    $data['cid'] = $_POST['cid'];
                    $ob->save($data); // 写入用户数据到数据库 */
                }
                $this->redirect('/bizcard/account/hash/'.session('info.hash'));
            }else{
                $this->error("二维码上传失败!");
            }
            return;
        }
        
        $result = $ob->where(array("cid"=>session("info.cid")))->find();
        

        $this->assign("info", $result);
        $this->display("Bizcard:uploadWxTwo");
        return;
    }
    
    /*查看微信二维码*/
    function showWxTwo(){
    	$ob = M('csl_customer');
    	$result = $ob->where(array("hash"=>$_GET['hash']))->find();

        $this->assign("info", $result);
        $this->display("Bizcard:showWxTwo");
        return;
    }
    
    
    
    
    //名片网址二维码
    function introqrcode(){
    	$hash = $_GET['hash'];
//     	if(is_file(DATA_PATH.$hash.'.png')){
//     		readfile(DATA_PATH.$hash.'.png');
//     		return ;
//     	}
    	
    	$ob = M("csl_customer");
    	$info = $ob->where(array('hash'=>$hash))->find();
    	if($info){
    		vendor('phpqrcode.phpqrcode');
    		QRcode::png("http://25mp.cn/card/".$hash,DATA_PATH.$hash.'.png'
    				,QR_ECLEVEL_L,15);
    		readfile(DATA_PATH.$hash.'.png');
    		return ;
    	}
    }
    
    //一键保存二维码
    function bizqrcode(){
    	
    	$hash = $_GET['hash'];
//     	if(is_file(DATA_PATH.$hash.'_bizcard.png')){
//     		readfile(DATA_PATH.$hash.'_bizcard.png');
//     		return ;
//     	}
    	
    	$ob = M("csl_customer");
    	$info = $ob->where(array('hash'=>$hash))->find();
    	if($info){
    		vendor('phpqrcode.phpqrcode');
    		

    		$str =
"BEGIN:VCARD
VERSION:4.0
FN:{$info[name]}
ORG:{$info[company]}
TITLE:{$info[title]}
TEL;TYPE=work,voice;VALUE=uri:{$info[mobile]}
TEL;TYPE=home,voice;VALUE=uri:{$info[telephone]}
ADR;TYPE=WORK:;;{$info[address]}
URL:http://25mp.cn/card/{$info[hash]}
NOTE:http://25mp.cn/card/{$info[hash]}
EMAIL:{$info[email]}
REV:".date('Y-m-d H:i:s')."
END:VCARD";

    		QRcode::png($str,DATA_PATH.$hash.'_bizcard.png',QR_ECLEVEL_L,15);
    		readfile(DATA_PATH.$hash.'_bizcard.png');
    		return ;
    	}
    	
    }

    
    // NOTE:http://25mp.cn/card/{$info[hash]}
    //ADR;TYPE=WORK:;;http://25mp.cn/card/{$info[hash]}
    //     		URL:http://25mp.cn/card/{$info[hash]}
    // X-QQ:{$info[qq]}
    // TEL;WORK;FAX:{$info[fax]}
    //     		EMAIL:{$info[email]} 
    
    //     		$str =
    // "BEGIN:VCARD
    // VERSION:3.0
    // FN:{$info[name]}
    // ORG:{$info[company]}
    // TITLE:{$info[title]}
    // TEL;TYPE=CELL,VOICE:{$info[mobile]}
    // TEL;TYPE=WORK,VOICE:{$info[telephone]}
    // EMAIL;TYPE=PREF,INTERNET:{$info[email]}
    // EMAIL;TYPE=PREF,INTERNET:http://25mp.cn/card/{$info[hash]}
    // REV:".date('Y-m-d H:i:s')."
    // END:VCARD";
    
    
    
//     VERSION:3.0
//     FN:梁青
//     ORG:厦门互云网络科技有限公司
//     TITLE:总经理 | GM
//     TEL;TYPE=CELL,VOICE:18106933881
//     TEL;TYPE=WORK,VOICE:18106933881
//     TEL;WORK;FAX:
//     X-QQ:147201158
//     EMAIL;TYPE=PREF,INTERNET:147201158@qq.com
//     URL:http://www.25mp.cn/showCard36
//     URL:http://www.25mp.cn/showCard/36
//     REV:20100426T103000Z
//     END:VCARD
    
//     BEGIN:VCARD
//     VERSION:2.1
//     N:姓;名
//     FN:姓名NICKNAME:nickName
//     ORG:公司;部门
//     TITLE:职位
//     NOTE;ENCODING=QUOTED-PRINTABLE:=C6=E4=CB=FB
//     TEL;WORK;VOICE:电话1
//     TEL;WORK;VOICE:电话2
//     TEL;HOME;VOICE:电话1
//     TEL;HOME;VOICE:电话2
//     TEL;CELL;VOICE:
//     TEL;PAGER;VOICE:0755
//     TEL;WORK;FAX:传真
//     TEL;HOME;FAX:传真
//     ADR;WORK:;;单位地址;深圳;广东;433000;国家
//     LABEL;WORK;ENCODING=QUOTED-PRINTABLE:=B5=A5=CE=BB=B5=D8=D6=B7
//     =C9=EE=DB=DA
//     =B9=E3=B6=AB
//     433000
//     =B9=FA=BC=D2
//     ADR;HOME;POSTAL;PARCEL:;;街道地址;深圳;广东;433330;中国
//     LABEL;HOME;ENCODING=QUOTED-PRINTABLE:=BD=D6=B5=C0=B5=D8=D6=B7
//     =C9=EE=DB=DA
//     =B9=E3=B6=AB
//     433330
//     =D6=D0=B9=FA
//     URL:网址
//     URL:单位主页
//     EMAIL;PREF;INTERNET:邮箱地址
//     X-QQ:38394246
//     X-ICQ:icq
//     X-WAB-GENDER:2
//     REV:20060220T180305Z
    
    function pay_mobile(){
    	 
    	$alipay = new Alipay([
    			// 支付完成异步返回地址
    			'notify_url' => 'http://'.$_SERVER['HTTP_HOST'].'/OrderCheck/AliNotify',
    			// 支付完成同步返回地址
    			'return_url' => 'http://'.$_SERVER['HTTP_HOST'].'/',
    			// 支付宝商家 ID
    			'partner'      => C("ALIPAY_PARTNER"),
    			// 支付宝商家 KEY
    			'key'          => C("ALIPAY_KEY"),
    			// 支付宝商家注册邮箱
    			'seller_email' => C("ALIPAY_EMAIL")
    	], 'wap');
    	$params = $alipay->prepareMobileTradeData(array(
    			'out_trade_no'      => '100000'.time(),
    			'subject'           => '名片',
    			'total_fee'         => '0.01',
    			'body'              => '名片',
    			'show_url'          => 'http://'.$_SERVER['HTTP_HOST'].'/index/Home/init',
    			'anti_phishing_key' => '',
    			'exter_invoke_ip'   => '',
    			'it_b_pay'          => '2m',
    			'_input_charset'    => 'utf-8'
    	));
    	$body = $alipay->buildRequestFormHTML($params, 'get');
    	// 输出 HTML 到浏览器，JS 会自动发起提交
    	echo $body;
    	
    }

    function pay_web(){
    	
    	$alipay = new Alipay([
    		// 支付完成异步返回地址
		    'notify_url' => 'http://'.$_SERVER['HTTP_HOST'].'/OrderCheck/AliNotify',
		    // 支付完成同步返回地址
		    'return_url' => 'http://'.$_SERVER['HTTP_HOST'].'/',
		    // 支付宝商家 ID
		    'partner'      => C("ALIPAY_PARTNER"),
		    // 支付宝商家 KEY
		    'key'          => C("ALIPAY_KEY"),
		    // 支付宝商家注册邮箱
		    'seller_email' => C("ALIPAY_EMAIL")
    	]);
    	$body = $alipay->buildRequestFormHTML(array(
    			'out_trade_no'      => '10000002',
    			'subject'           => '名片',
    			'total_fee'         => '0.01',
    			'body'              => '名片',
    			'show_url'          => 'http://'.$_SERVER['HTTP_HOST'].'/index/Home/init',
    			'anti_phishing_key' => '',
    			'exter_invoke_ip'   => '',
    			'it_b_pay'          => '2m',
    			'_input_charset'    => 'utf-8'
    	));
    	// 输出 HTML 到浏览器，JS 会自动发起提交
    	echo $body;
    	
//         Vendor('phpqrcode.phpqrcode','','.php');
    
//         $png = TEMP_PATH.'/'.rand(1000,9999).'.jpg';
//         $url = "weixin://wxpay/bizpayurl?pr=hg3ZS7R";
    
//         $s = QRcode::png($url,$png,QR_ECLEVEL_L,3,4);
    
//         $image_file = $png;
//         $image_info = getimagesize($image_file);
//         $base64_image_content = "data:{$image_info['mime']};base64," . chunk_split(base64_encode(file_get_contents($image_file)));
//         @unlink($image_file);
    
//         $s['img'] = $base64_image_content;
//         $s['status'] = 1;
//         Log::write("s==".print_r($s, true));
//         echo Encode($s);
    }
    
    
    
}